home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from ZSI import _copyright, _floattypes, _inttypes, _get_idstr, EvaluateException
- from ZSI.TC import TypeCode, SimpleType
- from ZSI.wstools.Namespaces import SCHEMA
- import operator
- import re
- import time as _time
- from time import mktime as _mktime, localtime as _localtime, gmtime as _gmtime
- from datetime import tzinfo as _tzinfo, timedelta as _timedelta, datetime as _datetime
- from math import modf as _modf
- _niltime = [
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0]
- _zero = _timedelta(0)
- _dstoffset = _stdoffset = _timedelta(seconds = -(_time.timezone))
- if _time.daylight:
- _dstoffset = _timedelta(seconds = -(_time.altzone))
-
- _dstdiff = _dstoffset - _stdoffset
-
- class _localtimezone(_tzinfo):
-
- def dst(self, dt):
- tt = _localtime(_mktime((dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)))
- if tt.tm_isdst > 0:
- return _dstdiff
-
- return _zero
-
-
- def tzname(self, dt):
- tt = _localtime(_mktime((dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)))
- return _time.tzname[tt.tm_isdst > 0]
-
-
- def utcoffset(self, dt):
- tt = _localtime(_mktime((dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)))
- if tt.tm_isdst > 0:
- return _dstoffset
-
- return _stdoffset
-
-
-
- class _fixedoffset(_tzinfo):
-
- def __init__(self, offset):
- self._fixedoffset__offset = _timedelta(minutes = offset)
-
-
- def dst(self, dt):
- return _zero
-
-
- def tzname(self, dt):
- return 'server'
-
-
- def utcoffset(self, dt):
- return self._fixedoffset__offset
-
-
-
- def _dict_to_tuple(d):
- retval = _niltime[:]
- for k, i in (('Y', 0), ('M', 1), ('D', 2), ('h', 3), ('m', 4)):
- v = d.get(k)
- if v:
- retval[i] = int(v)
- continue
-
- v = d.get('s')
- if v:
- (msec, sec) = _modf(float(v))
- retval[6] = int(round(msec * 1000))
- retval[5] = int(sec)
-
- v = d.get('tz')
- if v and v != 'Z':
- (h, m) = map(int, v.split(':'))
- offset = _localtimezone().utcoffset(_datetime.now())
- local_offset_hour = offset.seconds / 3600
- local_offset_min = offset.seconds % 3600 % 60
- if local_offset_hour > 12:
- local_offset_hour -= 24
-
- if local_offset_hour != h or local_offset_min != m:
- if h < 0:
- foff = _fixedoffset(-(abs(h) * 60 + m))
- else:
- foff = _fixedoffset(abs(h) * 60 + m)
- dt = _datetime(retval[0], retval[1], retval[2], retval[3], retval[4], retval[5], 0, foff)
- localdt = dt.astimezone(_localtimezone())
- retval[0] = localdt.year
- retval[1] = localdt.month
- retval[2] = localdt.day
- retval[3] = localdt.hour
- retval[4] = localdt.minute
- retval[5] = localdt.second
-
-
- if d.get('neg', 0):
- retval[0:5] = map(operator.__neg__, retval[0:5])
-
- return tuple(retval)
-
-
- class Duration(SimpleType):
- parselist = [
- (None, 'duration')]
- lex_pattern = re.compile('^(?P<neg>-?)P((?P<Y>\\d+)Y)?((?P<M>\\d+)M)?((?P<D>\\d+)D)?(?P<T>T?)((?P<h>\\d+)H)?((?P<m>\\d+)M)?((?P<s>\\d*(\\.\\d+)?)S)?$')
- type = (SCHEMA.XSD3, 'duration')
-
- def text_to_data(self, text, elt, ps):
- if text is None:
- return None
-
- m = Duration.lex_pattern.match(text)
- if m is None:
- raise EvaluateException('Illegal duration', ps.Backtrace(elt))
-
- d = m.groupdict()
- if d['T'] and d['h'] is None and d['m'] is None and d['s'] is None:
- raise EvaluateException('Duration has T without time')
-
-
- try:
- retval = _dict_to_tuple(d)
- except ValueError:
- e = None
- raise EvaluateException(str(e))
-
- if self.pyclass is not None:
- return self.pyclass(retval)
-
- return retval
-
-
- def get_formatted_content(self, pyobj):
- if type(pyobj) in _floattypes or type(pyobj) in _inttypes:
- pyobj = _gmtime(pyobj)
-
- d = { }
- pyobj = tuple(pyobj)
- if 1 in map((lambda x: x < 0), pyobj[0:6]):
- pyobj = map(abs, pyobj)
- neg = '-'
- else:
- neg = ''
- val = '%sP%dY%dM%dDT%dH%dM%dS' % (neg, pyobj[0], pyobj[1], pyobj[2], pyobj[3], pyobj[4], pyobj[5])
- return val
-
-
-
- class Gregorian(SimpleType):
- lex_pattern = None
- tag = None
- format = None
-
- def text_to_data(self, text, elt, ps):
- if text is None:
- return None
-
- m = self.lex_pattern.match(text)
- if not m:
- raise EvaluateException('Bad Gregorian: %s' % text, ps.Backtrace(elt))
-
-
- try:
- retval = _dict_to_tuple(m.groupdict())
- except ValueError:
- e = None
- raise
-
- if self.pyclass is not None:
- return self.pyclass(retval)
-
- return retval
-
-
- def get_formatted_content(self, pyobj):
- if type(pyobj) in _floattypes or type(pyobj) in _inttypes:
- pyobj = _gmtime(pyobj)
-
- d = { }
- pyobj = tuple(pyobj)
- if 1 in map((lambda x: x < 0), pyobj[0:6]):
- pyobj = map(abs, pyobj)
- d['neg'] = '-'
- else:
- d['neg'] = ''
- ms = pyobj[6]
- if not ms or not hasattr(self, 'format_ms'):
- d = {
- 'Y': pyobj[0],
- 'M': pyobj[1],
- 'D': pyobj[2],
- 'h': pyobj[3],
- 'm': pyobj[4],
- 's': pyobj[5] }
- return self.format % d
-
- if ms > 999:
- raise ValueError, 'milliseconds must be a integer between 0 and 999'
-
- d = {
- 'Y': pyobj[0],
- 'M': pyobj[1],
- 'D': pyobj[2],
- 'h': pyobj[3],
- 'm': pyobj[4],
- 's': pyobj[5],
- 'ms': ms }
- return self.format_ms % d
-
-
-
- class gDateTime(Gregorian):
- parselist = [
- (None, 'dateTime')]
- lex_pattern = re.compile('^(?P<neg>-?)(?P<Y>\\d{4,})-(?P<M>\\d\\d)-(?P<D>\\d\\d)T(?P<h>\\d\\d):(?P<m>\\d\\d):(?P<s>\\d*(\\.\\d+)?)(?P<tz>(Z|([-+]\\d\\d:\\d\\d))?)$')
- (tag, format) = ('dateTime', '%(Y)04d-%(M)02d-%(D)02dT%(h)02d:%(m)02d:%(s)02dZ')
- format_ms = format[:-1] + '.%(ms)03dZ'
- type = (SCHEMA.XSD3, 'dateTime')
-
-
- class gDate(Gregorian):
- parselist = [
- (None, 'date')]
- lex_pattern = re.compile('^(?P<neg>-?)(?P<Y>\\d{4,})-(?P<M>\\d\\d)-(?P<D>\\d\\d)(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('date', '%(Y)04d-%(M)02d-%(D)02dZ')
- type = (SCHEMA.XSD3, 'date')
-
-
- class gYearMonth(Gregorian):
- parselist = [
- (None, 'gYearMonth')]
- lex_pattern = re.compile('^(?P<neg>-?)(?P<Y>\\d{4,})-(?P<M>\\d\\d)(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('gYearMonth', '%(Y)04d-%(M)02dZ')
- type = (SCHEMA.XSD3, 'gYearMonth')
-
-
- class gYear(Gregorian):
- parselist = [
- (None, 'gYear')]
- lex_pattern = re.compile('^(?P<neg>-?)(?P<Y>\\d{4,})(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('gYear', '%(Y)04dZ')
- type = (SCHEMA.XSD3, 'gYear')
-
-
- class gMonthDay(Gregorian):
- parselist = [
- (None, 'gMonthDay')]
- lex_pattern = re.compile('^(?P<neg>-?)--(?P<M>\\d\\d)-(?P<D>\\d\\d)(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('gMonthDay', '---%(M)02d-%(D)02dZ')
- type = (SCHEMA.XSD3, 'gMonthDay')
-
-
- class gDay(Gregorian):
- parselist = [
- (None, 'gDay')]
- lex_pattern = re.compile('^(?P<neg>-?)---(?P<D>\\d\\d)(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('gDay', '---%(D)02dZ')
- type = (SCHEMA.XSD3, 'gDay')
-
-
- class gMonth(Gregorian):
- parselist = [
- (None, 'gMonth')]
- lex_pattern = re.compile('^(?P<neg>-?)---(?P<M>\\d\\d)(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('gMonth', '---%(M)02dZ')
- type = (SCHEMA.XSD3, 'gMonth')
-
-
- class gTime(Gregorian):
- parselist = [
- (None, 'time')]
- lex_pattern = re.compile('^(?P<neg>-?)(?P<h>\\d\\d):(?P<m>\\d\\d):(?P<s>\\d*(\\.\\d+)?)(?P<tz>Z|([-+]\\d\\d:\\d\\d))?$')
- (tag, format) = ('time', '%(h)02d:%(m)02d:%(s)02dZ')
- format_ms = format[:-1] + '.%(ms)03dZ'
- type = (SCHEMA.XSD3, 'time')
-
- if __name__ == '__main__':
- print _copyright
-
-